.FEATURE labels_without_colons

.IMPORT __SCRN1_LOAD__
.IMPORT __SCRN2_LOAD__
.IMPORT __CHARSET_LOAD__
.IMPORT scrdata, colrdata, logobgcolor
.IMPORT text,colors
.IMPORT __MUSIC_LOAD__

pich     = 11
texty    = 11
irqline  = texty*8+47
splitline = texty*8+47+8

scrlh    = 13
dummy    = $0340
scrn1    = __SCRN1_LOAD__
scrn2    = __SCRN2_LOAD__
scrlscradr = texty*$28+scrn2
colrscradr = texty*$28+$d800
musicplay = __MUSIC_LOAD__
logo18bits = $28
scrl18bits = $36

.SEGMENT "CODE2"
;Use aligned segment so that the irq is stable independent
;of the memory location of the code

.EXPORT _partyon=*
         lda #$36
         sta 1

         jsr irqinit
				 lda #0
				 tax
				 tay
				 dec 1
				 jsr musicplay
				 inc 1

         lsr $d019
         cli
         jmp *
waitretrace:
.EXPORT _waitretrace = waitretrace
			   lda $d011
         bpl *-3
         lda $d011
         bmi *-3
         rts
;---------------------------------------
d011val  .byte $07
;---------------------------------------

irq      lsr $d019

				 ;dec $d020				
  			 
  			 lda (0,x)
				  
         lda $d011
         ora #$70
         sta $d011
         lda #scrl18bits
         sta $d018
         lda #8
         sta $d016
         lda #0
         sta $d021

         lda #$70
         ora d011val
         sta $d011

         lda #splitline
         cmp $d012
         bne *-3
				 
         lda $d011
         and #$07
         cmp #7
         beq flickerweg
         lsr dummy
         lsr dummy
         lsr dummy
         lsr dummy
         lsr dummy
         lsr dummy
flickerweg
         ora #$10
         sta $d011
					
				 dec 1
				 jsr musicplay+3
				 inc 1
				 
         lda #<irq2
         sta $0314
         lda #>irq2
         sta $0315
         lda #250
         sta $d012

         ;inc $d020

         jmp $ea81

;---------------------------------------

irq2     lsr $d019

         lda #<irq
         sta $0314
         lda #>irq
         sta $0315
         lda #irqline
         sta $d012

         lda #logo18bits
         sta $d018
         lda #$18
         sta $d016
         lda #$38
         sta $d011
         lda logobgcolor
         sta $d021

         ;dec $d020
         jsr textscroll
         ;inc $d020

         jmp $ea81

         rts
;---------------------------------------
.CODE
textscroll lda $dc01
				 and #16
				 beq nohardscroll
				 
				 dec scrlspd
         bmi softscroll
nohardscroll:
         rts
softscroll:
         lda #4
         sta scrlspd

         dec d011val
         bpl nohardscroll

         lda #7
         sta d011val

         ldx #0
scrllin
         lda scrlscradr+(1*$28),x
         sta scrlscradr+(0*$28),x
         lda scrlscradr+(2*$28),x
         sta scrlscradr+(1*$28),x
         lda scrlscradr+(3*$28),x
         sta scrlscradr+(2*$28),x
         lda scrlscradr+(4*$28),x
         sta scrlscradr+(3*$28),x
         lda scrlscradr+(5*$28),x
         sta scrlscradr+(4*$28),x
         lda scrlscradr+(6*$28),x
         sta scrlscradr+(5*$28),x
         lda scrlscradr+(7*$28),x
         sta scrlscradr+(6*$28),x
         lda scrlscradr+(8*$28),x
         sta scrlscradr+(7*$28),x
         lda scrlscradr+(9*$28),x
         sta scrlscradr+(8*$28),x
         lda scrlscradr+(10*$28),x
         sta scrlscradr+(9*$28),x
         lda scrlscradr+(11*$28),x
         sta scrlscradr+(10*$28),x
         lda scrlscradr+(12*$28),x
         sta scrlscradr+(11*$28),x
         lda scrlscradr+(13*$28),x
         sta scrlscradr+(12*$28),x

         lda colrscradr+(1*$28),x
         sta colrscradr+(0*$28),x
         lda colrscradr+(2*$28),x
         sta colrscradr+(1*$28),x
         lda colrscradr+(3*$28),x
         sta colrscradr+(2*$28),x
         lda colrscradr+(4*$28),x
         sta colrscradr+(3*$28),x
         lda colrscradr+(5*$28),x
         sta colrscradr+(4*$28),x
         lda colrscradr+(6*$28),x
         sta colrscradr+(5*$28),x
         lda colrscradr+(7*$28),x
         sta colrscradr+(6*$28),x
         lda colrscradr+(8*$28),x
         sta colrscradr+(7*$28),x
         lda colrscradr+(9*$28),x
         sta colrscradr+(8*$28),x
         lda colrscradr+(10*$28),x
         sta colrscradr+(9*$28),x
         lda colrscradr+(11*$28),x
         sta colrscradr+(10*$28),x
         lda colrscradr+(12*$28),x
         sta colrscradr+(11*$28),x
         lda colrscradr+(13*$28),x
         sta colrscradr+(12*$28),x
getnewtextagain:
coladrmod = *+1
         lda colors,x ;colorram has always highbits set $fx
         cmp #$10
         bne notextreset ;use $10 as identification for text end

				 jsr textreset
				 jmp nextchar
notextreset:				 
         sta colrscradr+(scrlh*$28),x
				 
txtadrmod = *+1
         lda text,x
         sta scrlscradr+(scrlh*$28),x
nextchar:
         inx
         cpx #$28
         bcs *+5
         jmp scrllin

         cmp #$ff
         beq textreset

         lda txtadrmod
         clc
         adc #$28
         sta txtadrmod
         bcc *+5
         inc txtadrmod+1

         lda coladrmod
         clc
         adc #$28
         sta coladrmod
         bcc *+5
         inc coladrmod+1

         rts
textreset
         lda #<text
         sta txtadrmod
         lda #>text
         sta txtadrmod+1

         lda #<colors
         sta coladrmod
         lda #>colors
         sta coladrmod+1
         rts
scrlspd  .byte 0
;---------------------------------------
irqinit  lda #$7f
         sta $dc0d
         bit $dc0d

         lda #$81
         sta $d01a

         lda #250
         sta $d012

         lda #<irq2
         sta $0314
         lda #>irq2
         sta $0315

         rts
